from pydantic_settings import BaseSettings
from typing import List, Optional

class Settings(BaseSettings):
    """
    应用配置类
    使用pydantic-settings管理配置参数
    """
    
    # 应用基本配置
    app_name: str = "AIGD100 API"
    app_version: str = "1.0.0"
    debug: bool = False
    
    # 服务器配置
    host: str = "0.0.0.0"
    port: int = 8000
    
    # CORS配置
    allowed_origins: List[str] = ["*"]
    allowed_methods: List[str] = ["*"]
    allowed_headers: List[str] = ["*"]
    
    # 数据库配置
    database_url: str
    
    # Redis配置
    redis_url: str = "redis://localhost:6379/0"
    
    # 阿里云短信配置
    aliyun_access_key_id: str
    aliyun_access_key_secret: str
    aliyun_sms_sign_name: str
    aliyun_sms_template_code: str
    
    # JWT配置
    secret_key: str
    algorithm: str = "HS256"
    access_token_expire_minutes: int = 1440
    
    # 腾讯云短信配置（可选）
    tencent_secret_id: Optional[str] = ""
    tencent_secret_key: Optional[str] = ""
    tencent_sms_sdk_app_id: Optional[str] = ""
    tencent_sms_sign_name: Optional[str] = ""
    tencent_sms_template_id: Optional[str] = ""
    
    # 微信配置
    wechat_app_id: str = ""
    wechat_app_secret: str = ""
    wechat_public_app_id: str
    wechat_public_app_secret: str
    wechat_token: str = ""
    wechat_encoding_aes_key: str = ""
    wechat_original_id: str = ""
    
    # 星火大模型配置
    spark_app_id: str = "2f94a9b4"
    spark_api_key: str = "f1b415044f78ddfed873864a9756789b"
    spark_api_secret: str = "NzZjMGRhYWY3MDFhYWIzZmIzZDY2MTkw"
    spark_lite_url: str = "wss://spark-api.xf-yun.com/v1.1/chat"
    
    # 文件上传配置
    upload_max_size: str
    avatar_max_size: str
    
    class Config:
        """
        配置类设置
        """
        env_file = ".env"
        env_file_encoding = "utf-8"

# 创建全局配置实例
settings = Settings()

def get_settings() -> Settings:
    """
    获取应用配置实例
    
    Returns:
        Settings: 配置实例
    """
    return settings